package com.aa;
import java.util.ArrayList;
import java.util.HashMap;


import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ChongZhiListActivity extends Activity {
	private TextView mTitileView;
	private Button mbtnTitleBack;
	private TextView mtvTitleCenter;
	private CornerListView mCornerListView;
	private int[] menu_image_array = { R.drawable.ka_icon_14, R.drawable.ka_icon_15, R.drawable.ka_icon_3, R.drawable.yaloeka, R.drawable.more_new_info };
	private int[] menu_name_array = { R.string.app_chongzhika_1, R.string.app_chongzhika_2, R.string.app_chongzhika_4, R.string.app_chongzhika_3, R.string.more_title_1 };
	private SimpleAdapter getMenuAdapter(int[] pImages, int[] pText)
	{
	    ArrayList _ArrayList = new ArrayList();
	    for (int i = 0; ; i++)
	    {
	      if (i >= pImages.length)
	        return new SimpleAdapter(this, _ArrayList, R.layout.more_list_item, new String[] { "title", "img" }, new int[] { R.id.title, R.id.img });
	      HashMap _HashMap = new HashMap();
	      
	      _HashMap.put("title", getString(pText[i]));
	      _HashMap.put("img", Integer.valueOf(pImages[i]));
	      _ArrayList.add(_HashMap);
	    }
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chongzhilist);
		initView();
		bindData();
		initListener();
	}
	
	private void initView(){
		mbtnTitleBack = (Button)findViewById(R.id.btn_title_back);
		mbtnTitleBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
				
			}
		});
		mtvTitleCenter = (TextView)findViewById(R.id.tv_title_center);
		mtvTitleCenter.setText(R.string.chongzhi_zhcz);
		mCornerListView = (CornerListView)findViewById(R.id.chongzhi_list);
	}
	
	private void bindData(){
		mCornerListView.setAdapter(getMenuAdapter(menu_image_array, menu_name_array));
	}
	
	private void initListener(){
		mCornerListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
			if (arg2 < 4) {
				if (Common.iMyPhoneNumber.length() == 0) {
					Toast.makeText(ChongZhiListActivity.this, R.string.app_tip_bangding, 3000).show();
					return;					
				}
				String _Name = getString(menu_name_array[arg2]);
				
				Bundle _Bundle = new Bundle();
				_Bundle.putInt("TYPE", arg2);
				_Bundle.putString("NAME", _Name);
				
				Intent _Intent = new Intent();
				_Intent.putExtra("KEY", _Bundle);
				_Intent.setClass(ChongZhiListActivity.this, ChongZhiActivity.class);
				startActivity(_Intent);
				return;
			}		
			
			if (arg2 == 4) {
				Intent _Intent = new Intent();
				_Intent.setClass(ChongZhiListActivity.this, NewFavourableActivity.class);
				startActivity(_Intent);
			}
		}
			
	});
   }
	
}
